package top.huahaizhi.zhihu.daily.util;

        import android.content.Context;
        import android.graphics.Bitmap;
        import android.widget.ImageView;

        import com.squareup.picasso.MemoryPolicy;
        import com.squareup.picasso.Picasso;

/**
 * 海志 在 2017/8/3 0003 创建
 *
 * @mail huahaizhi@gmail.com
 * 功能：
 */

public class Utils {

    private static final String TAG = "LoadImageUtils";

    private static Utils utils;

    private Context context;

    private Utils(Context context) {
        this.context = context;
    }


    public static Utils getInstance(Context context) {
        if (utils == null)
            synchronized (Utils.class) {
                if (utils == null)
                    utils = new Utils(context);
            }
        return utils;
    }

    public void loadImage(String url, ImageView view, int replace, int errorImg) {
        if (view != null)
            if (replace != -1)
                Picasso.with(context).load(url).config(Bitmap.Config.RGB_565).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(errorImg).placeholder(replace).into(view);
            else
                Picasso.with(context).load(url).config(Bitmap.Config.RGB_565).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(errorImg).into(view);
    }
}